GBML manual / Stacks

stack_empty

True if target currently holds no items, false otherwise. The way to know, BEFORE calling stack_pop/stack_peek, whether the value they would give back is a real item or just the empty-container default.

Syntax

stack_empty(target) -> bool

Arguments

NameType
targetstack

Returns

bool

Description

true if target currently holds no items, false otherwise. The same answer as stack_length(target) == 0, spelled as its own question.

This is the way to know, BEFORE calling stack_pop/stack_peek, whether the value either would give back is a real item or just the empty-container default - useful anywhere the difference matters (an undo button that should gray itself out once there is nothing left to undo, say).

Example

/// @type {stack<int>}
var history = [];
var nothing_to_undo = stack_empty(history); // true
stack_push(history, 1);
var has_moves = stack_empty(history); // false
A real capture - an empty stack, stack_empty answering YESA real capture - an empty stack, stack_empty answering YES
A real capture - an empty stack, stack_empty answering YES
The same stack after stack_push(history, 1) - stack_empty now answers NOThe same stack after stack_push(history, 1) - stack_empty now answers NO
The same stack after stackpush(history, 1) - stackempty now answers NO

On the GBA

Just the vector's empty() - O(1).

See also: stack_popstack_peekstack_lengthstack_pushData containers